
class TrainSqlMap(object):
    FIND_ALL_CLASSIFY = 'SELECT s.status_id,s.sort_value,s.status_name FROM aoa_status_list s where s.status_model="aoa_train" ORDER BY s.sort_value'
    my_read = "select t.id,t.read_time,t.title,t.read_times from (select t1.*,t2.read_user,t2.train,t2.read_time from aoa_train_record as t2 left join aoa_train as t1 on t2.train=t1.id where read_user={user_id} order by t2.read_time desc) as t group by t.train"
    classify = "select distinct t2.type_name from aoa_train as t1 inner join aoa_type_list as t2 on t1.classify=t2.type_id"
    classify_inquire = "select t1.id,t1.title,t1.create_time,t1.read_times,t1.is_public,t1.author as author_id,count(t2.train) as file_num,t3.real_name as author_name from aoa_train as t1 left join aoa_train_files as t2 on t1.id=t2.train inner join aoa_user as t3 on t1.author=t3.user_id where t1.classify={classify} group by t1.id"
    article = "select t1.id,t1.read_times,t1.title,t1.create_time,t1.author as author_id,t1.content,t3.real_name as author_name from aoa_train as t1 inner join aoa_user as t3 on t1.author=t3.user_id where t1.id={id}"
    TRAIN_LIST = "select t1.id,t1.read_times,t1.title,t2.real_name,t1.create_time,t1.is_public from aoa_train as t1 inner join aoa_user as t2 on t1.author=t2.user_id"
    FILE_NUM = "select count(id) as file_num from aoa_train_files where train={id}"

    FILE = "select id as attach_id,file_name as attachment_name from aoa_train_files where train={id}"

    INSERT_RECORD = "insert into aoa_train_record(read_time, read_user, train) values(now(),{user_id},{id})"
    UPDATE_TRAIN = "update aoa_train set read_times=read_times+1 where id={id}"
    FILTER_PARAMS = {
        "query_str": "t1.title like '%{query_str}%'",
        "classify":"t1.classify={classify}",
        "query_str_read": "t.title like '%{query_str_read}%'"
    }